<template>
    <div>
        <h3>管理员登录页面</h3>
        <table class="table">
            <tr>
                <td>账号:</td>
                <td>
                    <input type="text" placeholder="请输入账号" v-model="data.name">
                </td>
            </tr>
            <tr>
                <td>密码:</td>
                <td>
                    <input type="password" placeholder="请输入密码" v-model="data.pass">
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="登录" class="btn btn-success" @click="lgoin">
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
import { useStore } from '@/stores/info';
const userst=useStore();

const router=useRouter();
const route=useRoute();
const data=ref({
    name:"",
    pass:""
})
const lgoin=()=>{
    if(data.value.name==""){
        alert('账号不能为空！')
        return
    }
    if(data.value.pass==""){
        alert('密码不能为空！')
        return
    }
    axios.get("https://localhost:7237/api/Men/Login",{params:data.value}).then(res=>{
        if(res.data==1){
            alert('账号错误');
        }
        if(res.data==2){
            alert('密码错误');
        }
        if(res.data==3){
            alert('登录成功！');
            userst.usert.username=data.value.name;
            userst.usert.userpass=data.value.pass;
            router.push({path:"/menadd"})
        }
    })
}

</script>

<style scoped>

</style>